package request_manage_models

import (
	"errors"
	"storeManageApi/models/dbModels"
	"storeManageApi/utils"
)

type NewOutNotes struct {
	ActionNumber   int    `json:"actionNumber"`
	ActionUserName string `json:"actionUserName"`
	Description    string `json:"description"`
	GoodsUid       string `json:"goodsUid"`
	UseTo          string `json:"useTo"`
	UseUserName    string `json:"useUserName"`
	Depart         string `json:"depart"`
}

func (receiver NewOutNotes) ConvertOutNotes() dbModels.OutNotes {
	return dbModels.OutNotes{
		Base: dbModels.Base{
			Uid:         utils.RandomUid(),
			Description: receiver.Description,
		},
		ActionNumber:   receiver.ActionNumber,
		ActionUserName: receiver.ActionUserName,
		GoodsUid:       receiver.GoodsUid,
		UseTo:          receiver.UseTo,
		UseUserName:    receiver.UseUserName,
		Depart:         receiver.Depart,
	}
}

func (receiver NewOutNotes) Isvalidated() error {
	if receiver.GoodsUid == "" {
		return errors.New("操作物品不能为空")
	}
	if receiver.ActionNumber <= 0 {
		return errors.New("操作数量不合法")
	}
	if receiver.UseTo == "" {
		return errors.New("用途不能为空")
	}
	if receiver.ActionUserName == "" {
		return errors.New("操作人员姓名不合法")
	}
	if receiver.UseUserName == "" {
		return errors.New("领用人员姓名不合法")
	}
	if receiver.Depart == "" {
		return errors.New("领用部门不合法")
	}
	return nil
}
